<template>
  <Dialog v-model="dialogVisible" :max-height="400" :scroll="true" title="待阅详情">
    <el-descriptions :column="1" border style="text-align: center">
      <el-descriptions-item :width="25" label="待阅标题">
        {{ detailData.templateCode }}
      </el-descriptions-item>
      <el-descriptions-item label="发送人">
        {{ detailData.templateNickname }}
      </el-descriptions-item>
      <el-descriptions-item label="发送时间">
        {{ formatDate(detailData.createTime) }}
      </el-descriptions-item>

<!--      <el-descriptions-item label="是否已读">
        <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="detailData.readStatus" />
      </el-descriptions-item>-->
      <el-descriptions-item v-if="detailData.readStatus" label="阅读时间">
        {{ formatDate(detailData.readTime) }}
      </el-descriptions-item>
      <el-descriptions-item label="内容">
        {{ detailData.templateContent }}
      </el-descriptions-item>
      <el-descriptions-item label="操作" v-if="!detailData.readStatus">
        <el-button  type="primary" size="mini" @click="setRead">设为已阅</el-button>
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>
<script lang="ts" setup>
import { formatDate } from '@/utils/formatTime'
import * as NotifyMessageApi from '@/api/system/notify/message'

defineOptions({ name: 'MyNotifyMessageDetailDetail' })

const dialogVisible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as NotifyMessageApi.NotifyMessageVO) // 详情数据

/** 打开弹窗 */
const open = async (data: NotifyMessageApi.NotifyMessageVO) => {
  dialogVisible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    detailData.value = data
  } finally {
    detailLoading.value = false
  }
}
/**设置已阅*/
const setRead = () => {
  detailLoading.value = true
  NotifyMessageApi.updateNotifyMessageRead(detailData.value.id).then(() => {
    ElMessage.success('设置成功')
    detailData.value.readStatus = true
    detailData.value.readTime = new Date()
  }).finally(() => {
    detailLoading.value = false
  })
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
